package com.xmg.p2p.base.controller;

import com.xmg.p2p.base.domain.Userinfo;
import com.xmg.p2p.base.service.ISysDictService;
import com.xmg.p2p.base.service.IUserinfoService;
import com.xmg.p2p.base.util.JSONResult;
import com.xmg.p2p.base.util.RequireLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BasicInfoController {
    @Autowired
    private IUserinfoService userinfoService;
    @Autowired
    private ISysDictService sysDictService;

    @RequestMapping("basicInfo")
    @RequireLogin
    public String basicInfo(Model model) {
        model.addAttribute("userinfo", userinfoService.getCurrent());
        model.addAttribute("educationBackgrounds", sysDictService.selectByParentSn("educationBackground"));
        model.addAttribute("incomeGrades", sysDictService.selectByParentSn("incomeGrade"));
        model.addAttribute("marriages", sysDictService.selectByParentSn("marriage"));
        model.addAttribute("kidCounts", sysDictService.selectByParentSn("kidCount"));
        model.addAttribute("houseConditions", sysDictService.selectByParentSn("houseCondition"));
        return "userInfo";
    }

    @RequestMapping("basicInfo_save")
    @ResponseBody
    @RequireLogin
    public JSONResult basicInfoSave(Userinfo info) {
        userinfoService.updateBasicInfo(info);
        return new JSONResult();
    }
}
